package com.zmn.plat.services.impl.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.order.OrderItem;
import com.zmn.plat.persistence.interfaces.order.OrderItemDao;
import com.zmn.plat.services.interfaces.order.OrderItemService;

/**
 * @uthor nowind
 * @since 2018/9/22 09:50
 */
@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private OrderItemDao orderItemDao;

    @Override
    public OrderItem findByKey(Integer orderId) {
        return orderItemDao.findByKey(orderId);
    }

    @Override
    public Integer updateByKey(OrderItem orderItem) {
        if (orderItem.getUpdateTime() == null) {
            orderItem.setUpdateTime(DateUtil.getNow());
        }
        return orderItemDao.updateByKey(orderItem);
    }

    @Override
    public Integer insert(OrderItem orderItem) {

        if (orderItem.getUpdateTime() == null) {
            orderItem.setUpdateTime(DateUtil.getNow());
        }
        orderItem.setCreateTime(orderItem.getUpdateTime());

        return orderItemDao.insert(orderItem);
    }

    @Override
    public void deleteByKey(Integer orderId) {
        orderItemDao.deleteByKey(orderId);
    }
}
